$(document).ready(function () {
    //图表1投诉事项类型分布
    $.ajax({
        url: window.ViewContextPath + "/system/layui/getTsjbdjType",
        dataType: "json",
        type: "get",
        success: function (msg) {
            if (msg.data.length > 0) {
                var myChart = echarts.init(document.getElementById('main1'));
                var option = {
                    title: {
                        text: '',
                        subtext: '',
                        x: 'center'
                    },
                    tooltip: {
                        trigger: 'item',
                        formatter: "{a} <br/>{b} : {c} ({d}%)"
                    },
                    calculable: true,
                    series: [
                        {
                            name: '投诉事项类型',
                            type: 'pie',
                            radius: [30, 110],
                            center: ['50%', '50%'],
                            roseType: 'area',
                            data: msg.data
                        }
                    ]
                };
                myChart.setOption(option);
            }
        }
    });
    

    //图表2满意度城市覆盖率
    $.ajax({
        url: window.ViewContextPath + "/system/layui/getMuddType",
        dataType: "json",
        type: "get",
        success: function (msg) {
        	var data = msg.data;
        	console.log(data);
            if (data.length > 0) {
            	var city = [];
            	var num = [];
            	for(var i=0; i<data.length;i++){
            		city.push(data[i].city);
            		num.push(data[i].num);
            	}
            	var myChart = echarts.init(document.getElementById('main2'));
                var option = {
                    title: {
                        text: '',
                        subtext: ''
                    },
                    tooltip: {
                        trigger: 'axis'
                    },
                    grid: {
                        top: '10%',
                        left: '3%',
                        right: '3%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: [
                        {
                            type: 'category',
                            axisLabel: {  
                            	   rotate:30  
                            },  
                            data: city
                        }
                    ],
                    yAxis: [
                        {
                            type: 'value'
                        }
                    ],
                    series: [
                        {
                            name: '问卷数',
                            type: 'bar',
                            data: num,
                            barCategoryGap: '50%',
                            color: 'rgb(106, 138, 189)'

                        }
                    ]
                };
                myChart.setOption(option);
            }
        }
   	});

    //投诉已办理公示内容
    $.ajax({
        url: window.ViewContextPath + "/system/layui/getTsjbdj",
        dataType: "json",
        type: "get",
        success: function (data) {
            var msg = data.data;
            var html = "暂无数据!";
            if (msg.length > 0) {
                for (var i = 0; i < msg.length; i++) {
                    html += "<tr><td style='width: 150px; overflow: hidden;white-space: nowrap;text-overflow: ellipsis;'>" + msg[i].tsTitle + "</td><td>" + msg[i].tsPhoneno + "</td><td>" + new Date(msg[i].insTime).Format("yyyy-MM-dd") + "</td><td>已办结</td></tr>";
                    if (i == 4) {
                        break;
                    }
                }
            }
            $("#tsData").append(html);
        }
    });

    //毫秒转日期格式
    Date.prototype.Format = function (fmt) {
        var o = {
            "M+": this.getMonth() + 1, //月份
            "d+": this.getDate(), //日
            "h+": this.getHours(), //小时
            "m+": this.getMinutes(), //分
            "s+": this.getSeconds(), //秒
            "q+": Math.floor((this.getMonth() + 3) / 3), //季度
            "S": this.getMilliseconds() //毫秒
        };
        if (/(y+)/.test(fmt))
            fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt))
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    }
})